﻿namespace V8Bridge.FSharp

open System.Threading
open Jurassic

type internal JurassicCompiler() =

    let engine = ScriptEngine()
    let gate = obj()
        
    interface V8Bridge.Interface.IV8ScriptCompiler with
        member x.InitializeLibrary code =
            lock gate (fun _ ->
                let t = Thread((fun () -> engine.Execute(code)), 10 * 1048576)
                t.Start()
                t.Join()
            )

        member x.Compile(func, code) =
            engine.CallGlobalFunction<string>(func, code)
                    
